package com.eternal.permission.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.eternal.permission.entity.PermissionInfo;
import com.eternal.permission.dao.PermissionInfoMapper;
import com.eternal.permission.entity.enums.IsOpenEnum;
import com.eternal.permission.service.PermissionInfoService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import java.util.List;

/**
 * <p>
 * 基础权限表 服务实现类
 * </p>
 *
 * @author Eternal
 * @since 2018-08-26
 */
@Service
@CacheConfig(cacheNames = "permissionInfo")
@Transactional
public class PermissionInfoServiceImpl extends ServiceImpl<PermissionInfoMapper, PermissionInfo> implements PermissionInfoService {

    @Cacheable(keyGenerator = "keyGenerator")
    @Override
    public List<PermissionInfo> getAll() {
        Wrapper<PermissionInfo> wrapper = new EntityWrapper<>();
        wrapper.orderBy("sort");
        //wrapper.setSqlSelect("pi.p_id AS pId,pi.p_name,pi.p_parent_code");
        List<PermissionInfo> permissionInfos = this.baseMapper.selectList(wrapper);
        return permissionInfos;
    }

    @Override
    public Page<PermissionInfo> getPermission(Page<PermissionInfo> page) {
        Wrapper<PermissionInfo> wrapper = new EntityWrapper<>();
        wrapper.where("is_available={0}", "1");
        Page<PermissionInfo> permissionInfoPage = selectPage(page, wrapper);
        String a = "";
        String[] split = a.split("");

        return permissionInfoPage;
    }

    @Override
    public boolean openPermission(PermissionInfo permissionInfo) {
         boolean b = permissionInfo.updateById();
        return b;
    }

}
